package ipWhite

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/ipwhite"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddIpWhiteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 新增
func NewAddIpWhiteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddIpWhiteLogic {
	return &AddIpWhiteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddIpWhiteLogic) AddIpWhite(req *types.AddIpWhiteReq) (resp *types.Empty, err error) {

	u, err := l.svcCtx.SettingService.IpWhite.AddIpWhite(l.ctx, &ipwhite.AddIpWhiteReq{
		MerchantId: 1,
		Ip:         req.Ip,                     // ip
		Status:     rpc.StatusType(req.Status), // 是否开启,0:,关闭1:开启
		Remark:     req.Remark,                 // 备注
	})
	if err != nil {
		logc.Error(l.ctx, "AddIpWhite err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
